#include <outilsgeom.hpp>

namespace Life
{

double 
OutilsGeom::distance(node_type p1, node_type p2) {

    double res=0.0;

    for (uint i=0;i<p1.size();++i) {
        res+=(p2(i)-p1(i))*(p2(i)-p1(i));
    }

    return math::sqrt(res);
}


OutilsGeom::node_type 
OutilsGeom::calcul(node_type p1, node_type p2, node_type p3) {

double a=p2(1)-p1(1);
double b=p2(0)-p1(0);

double f1=-p2(0)*p1(1) + p1(0)*p2(1);
double f2=-a*p3(1) - b*p3(0);

double det=-a*a - b*b;

//ublas::matrix<double> Am1( 2,2 );

//Am1(0,0)=-a;

node_type res(2);

res(0) = (1./det)*(-a*f1 + b*f2);
res(1) = (1./det)*(b*f1 + a*f2);

return res;

}


}
